home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / GX Libraries / GraphicsStateLibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  2.5 KB  |  106 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        GraphicsStateLibrary.c
  4.  
  5.     Contains:    graphics libraries - graphics state routines 
  6.  
  7.     Written by:    Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Mike Reed, Oliver Steele, David Van Brink, Chris Yerga
  8.  
  9.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.          <1>      1/9/95    JD        First checked in.
  14. */
  15.  
  16. #include <Memory.h>
  17. #include "GraphicsLibraries.h"
  18. #include "GraphicsStateLibrary.h"
  19.  
  20. graphicsState lastGraphicsState = nil;
  21.  
  22. graphicsState NewGraphicsState(void)
  23. {
  24.    graphicsState state = (graphicsState) NewPtr(sizeof(graphicsStateRecord));
  25.    short i;
  26.    
  27.    IfErrorReturnNil(state == nil, out_of_memory);
  28.    for (i = gxEmptyType; i <= gxPictureType; i++)
  29.       state->defaultShapes[i - 1] = GXGetDefaultShape(i);
  30.    return lastGraphicsState = state;
  31. }
  32.  
  33. void DisposeGraphicsState(graphicsState state)
  34. {
  35.    NilParamReturn(state);
  36.    if (lastGraphicsState == state)
  37.       lastGraphicsState = nil;
  38.    DisposePtr((Ptr) state);
  39. }
  40.  
  41. void GetGraphicsState(graphicsState state)
  42. {
  43.    short i;
  44.    
  45.    NilParamReturn(state);
  46.    for (i = gxEmptyType; i <= gxPictureType; i++) {
  47.       gxShape def = GXGetDefaultShape(i);
  48.       if (state->defaultShapes[i - 1] != def) {
  49.          GXDisposeShape(state->defaultShapes[i - 1]);
  50.          state->defaultShapes[i - 1] = def;
  51.       }
  52.    }
  53. }
  54.  
  55. void SetGraphicsState(graphicsState state)
  56. {
  57.    short i;
  58.    
  59.    NilParamReturn(state);
  60.    for (i = gxEmptyType; i <= gxPictureType; i++)
  61.       GXSetDefaultShape(state->defaultShapes[i - 1]);
  62.    lastGraphicsState = state;
  63. }
  64.  
  65. graphicsState SwapGraphicsState(graphicsState state)
  66. {
  67.    graphicsState lastState = lastGraphicsState;
  68.    
  69.    if (lastGraphicsState)
  70.       SetGraphicsState(lastGraphicsState);
  71.    if (state)
  72.       SetGraphicsState(state);
  73.    lastGraphicsState = state;
  74.    return lastState;
  75. }
  76.  
  77. gxStyle SeparateShapeStyle(gxShape source)
  78. {
  79.    gxStyle old = GXCloneStyle(GXGetShapeStyle(source)), xnew = GXCopyToStyle(nil, old);
  80.    GXSetShapeStyle(source, xnew);
  81.    GXDisposeStyle(xnew);
  82.    return old;
  83. }
  84.  
  85. void ReuniteShapeStyle(gxShape target, gxStyle separate)
  86. {
  87.    GXSetShapeStyle(target, separate);
  88.    GXDisposeStyle(separate);
  89.    return;
  90. }
  91.  
  92. gxInk SeparateShapeInk(gxShape source)
  93. {
  94.    gxInk old = GXCloneInk(GXGetShapeInk(source)), xnew = GXCopyToInk(nil, old);
  95.    GXSetShapeInk(source, xnew);
  96.    GXDisposeInk(xnew);
  97.    return old;
  98. }
  99.  
  100. void ReuniteShapeInk(gxShape target, gxInk separate)
  101. {
  102.    GXSetShapeInk(target, separate);
  103.    GXDisposeInk(separate);
  104.    return;
  105. }
  106.